# -*- coding: utf-8 -*-
# author: ting.wei
# time: 2022/10/25
from appium.webdriver.common.appiumby import AppiumBy

from proj_spec.CLUE.mobile_po.clue_app_base_page import CLUEAppBasePage
from proj_spec.CLUE.mobile_po.followed_company_list_page import FollowedCompanyListPage


class FollowedCompanyPage(CLUEAppBasePage):
    """
    关注企业页面
    """
    _followed_company_locator_android = (AppiumBy.XPATH, "//*[@resource-id='focus.list']")
    _followed_company_locator_ios = (AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`label CONTAINS "pages/control/index"`]/XCUIElementTypeImage[1]')

    _main_page_locator_android = (AppiumBy.XPATH, "//*[contains(@resource-id,'tabTV') and contains(@text,'首页')]")
    _main_page_ios = (AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeButton[`label == "首页"`]')

    def to_followed_company_list_page(self):
        """
        跳转企业关注列表
        """
        self.find_element_and_click(getattr(self, '_followed_company_locator_' + self.os))
        return FollowedCompanyListPage(self.driver)

    def to_main(self):
        """
        回到首页
        """
        self.find_element_and_click(getattr(self, '_main_page_locator_' + self.os))